<%--<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>--%>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%--<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>--%>
<%--<!DOCTYPE html>--%>
<%--<html>--%>
<%--<head>--%>
<%--  <title>已接收私信</title>--%>
<%--  <link rel="icon" href="./favicon/favicon.ico" type="image/x-icon">--%>
<%--  <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">--%>
<%--</head>--%>
<%--<body class="container py-4">--%>
<%--<h4 class="mb-3">已接收私信</h4>--%>

<%--<c:if test="${empty receiveList}">--%>
<%--  <div class="alert alert-info">暂无记录</div>--%>
<%--</c:if>--%>

<%--<c:forEach items="${receiveList}" var="receive">--%>
<%--  <div class="card mb-2 ${receive.isRead == 1 ? '' : 'border-warning'}">--%>
<%--    <div class="card-body">--%>
<%--      <div class="d-flex justify-content-between">--%>
<%--        <span class="fw-bold">来自：${receive.senderName}</span>--%>
<%--        <small class="text-muted">--%>
<%--          <i class="bi bi-calendar"></i>--%>
<%--            ${receive.sentTime}--%>
<%--          <c:if test="${receive.isRead == 0}">--%>
<%--                        <span class="badge bg-warning ms-2">未读</span>--%>
<%--                      </c:if>--%>
<%--        </small>--%>


<%--      </div>--%>
<%--      <div class="mt-1">${receive.content}</div>--%>
<%--    </div>--%>
<%--  </div>--%>
<%--</c:forEach>--%>

<%--<a href="javascript:history.back()" class="btn btn-secondary btn-sm mt-3">返回</a>--%>
<%--</body>--%>
<%--</html>--%>




<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>已接收私信</title>
    <link rel="icon" href="./favicon/favicon.ico" type="image/x-icon">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/js/bootstrap.bundle.min.js"></script>
</head>
<body class="container py-4">
<h4 class="mb-3">已接收私信</h4>

<c:if test="${empty receiveList}">
    <div class="alert alert-info">暂无记录</div>
</c:if>

<c:forEach items="${receiveList}" var="receive">
    <div class="card mb-2 ${receive.isRead == 1 ? '' : 'border-warning'}" onclick="markAsRead(${receive.id})">
        <div class="card-body">
            <div class="d-flex justify-content-between">
                <span class="fw-bold">来自：${receive.senderName}</span>
                <small class="text-muted">
                    <i class="bi bi-calendar"></i>
                        ${receive.sentTime}
                    <c:if test="${receive.isRead == 0}">
                        <span class="badge bg-warning ms-2">未读</span>
                    </c:if>
                </small>
            </div>
            <div class="mt-1">${receive.content}</div>
        </div>
    </div>
</c:forEach>

<a href="javascript:history.back()" class="btn btn-secondary btn-sm mt-3">返回</a>

<script>
    function markAsRead(id) {
        $.post('${pageContext.request.contextPath}/messageServlet?method=markAsRead', { id: id })
            .done(function(data) {
                // 重新加载页面或更新特定消息的状态
                location.reload();
            })
            .fail(function() {
                alert('操作失败，请稍后重试');
            });
    }
</script>
</body>
</html>